#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author Jmz

names1 = {'jmz','joe','jack','ming'}
# 集合不可变类型。
for name in names1:
    print(name)
'''
# 字典和集合一样都是无序的，所以出来的结果也是无序的
ming
jack
joe
jmz
'''

if 'jmz' in names1:
    print('jmz 在names1 中')




names2 = {'jmz','jack','vavain','king'}


print('集合运算'.center(100,'-'))
#3、|合集
#4、&交集
#5、-差集
#6、^对称差集
#7、==  等于
#8、父集：>,>=
#9、子集：<,<=

print(names1|names2)  # 两者的合集
# {'joe', 'ming', 'vavain', 'king', 'jack', 'jmz'}

print(names1&names2)  # 连个的交集
# {'jack', 'jmz'}

print(names1-names2)  # 去除names1 中含有names2 的数据
# {'ming', 'joe'}

print(names1^names2)  # 合集-交集
# {'vavain', 'joe', 'ming', 'king'}

print(names1 == names2)

print({'jmz','qqc'} > {'qqc'})   # 前者是后者的父集
# True
print({'jmz','qqc'} < {'qqc'})   # 前者不是后者的子集
#False



print('去重'.center(100,'-'))

names = "jmz joe kitty nask egon jmz kitty qqc kitty vavian vavian"

# 方法一
name_l = names.split()
name_dic = {}
for name in name_l:
    if name in name_dic:
        name_dic[name] += 1
    else:
        name_dic[name] = 1

print(name_dic)

# 方法二
name_l = names.split()
name_dic = {}
for name in set(name_l):
    name_dic[name] = name_l.count(name)
print(name_dic)








